
use std::time::Duration;

use sdl2::pixels::Color;
use sdl2::rect::Rect;
use sdl2::Sdl;
use sdl2::event::Event;
use sdl2::keyboard::Keycode;


pub fn lesson1() {

    let sdl_context = sdl2::init().unwrap();

    let video = sdl_context.video().unwrap();
    let window = video.window("lesson1", 640, 480)
        .position_centered()
        .build().unwrap();

    let mut event_pump = sdl_context.event_pump().unwrap();
    let mut surface = window.surface(&event_pump).unwrap();

    surface.fill_rect(Rect::new(640/2 - 50, 480/2 - 30, 100, 60), Color::RGB(255, 0, 0));

    surface.update_window();

    'running: loop {
        for event in event_pump.poll_iter() {
            match event {
                Event::Quit {..} |
                Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
                    break 'running
                },
                _ => {}
            }
        }
        std::thread::sleep(Duration::new(0, 1_000_000_000u32 / 60));
    }

    // surface.finish();
}
